package demo3;

import java.util.Comparator;
import java.util.Arrays;

class Student {
    public String name;
    public int age;
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String toString() {
        return "Student{" + "name='" + this.name + "', " + "age=" + this.age + "}";
    }
}
class AgeComparator implements Comparator<Student> {
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
class NameComparator implements Comparator<Student> {
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class test3 {
    public static void main(String[] args) {
//        Student student1 = new Student("zhangsan",10);
//        Student student2 = new Student("lisi",20);
        AgeComparator ageComparator = new AgeComparator();
//        ageComparator.compare(student1, student2);
        Student[] students = {new Student("zhangsan",20),new Student("lisi",5),new Student("wangwu",10)};
        Arrays.sort(students, ageComparator);
        System.out.println(Arrays.toString(students));
    }
}
